package com.delistry.server.clientpacket;

import java.util.ArrayList;
import java.util.List;

public abstract class ClientPacketProcess implements Runnable {

	protected final int op;	
	public int getOP(){
		return op;
	}

	private final List<ClientPacket> workBuffer;

	protected ClientPacket PeekData() {
		if (workBuffer.size() == 0) {
			return null;
		}
		return workBuffer.get(0);
	}

	public void AddClientPacket(ClientPacket cp) {
		workBuffer.add(cp);
	}

	protected ClientPacketProcess(int op) {
		this.op = op;
		this.workBuffer = new ArrayList<ClientPacket>();
	}

	public final void Handle() {
		while (workBuffer.size() > 0) {
			HandleClientPacket();
			workBuffer.remove(0);
		}
	}

	protected void HandleClientPacket() {
		System.out.println("Packet Handle");
	}

	@Override
	public void run() {
		while (true) {
			Handle();
		}
	}
}
